import com.ktjy.entity.Concert;
import com.ktjy.service.ConcertService;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

public class Main {
    Logger logger= LoggerFactory.getLogger(Main.class);

    @Test
    public void selectConcert(){
        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        ConcertService concertService=(ConcertService)context.getBean("concertService");
        int pageSize=2;
        int pageIndex=2;
        int pageBegin=(pageIndex-1)*pageSize;
        List<Concert> list=concertService.selectConcert(pageSize,pageBegin);
        for (Concert concert:list){
            System.out.println(concert);
        }
    }

    @Test
    public void insertConcert() throws ParseException {
        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        ConcertService concertService=(ConcertService)context.getBean("concertService");
        int count=0;

        Concert concert=new Concert();
        concert.setConcertName("熊静");
        concert.setCity("北京");
        concert.setPrice(200);
        concert.setRecommend(1);
        Date date=new SimpleDateFormat("yyyy-MM-dd").parse("2024-12-9");
        concert.setStartTime(date);
        concert.setAddress("北京海淀区");

        count=concertService.insertConcert(concert);
        System.out.println(count);
    }

    @Test
    public void updateConcert() throws ParseException {
        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        ConcertService concertService=(ConcertService)context.getBean("concertService");
        int count=0;

        Concert concert=new Concert();
        concert.setConcertId(13);
        concert.setConcertName("熊静-修改");
        concert.setCity("北京");
        concert.setPrice(200);
        concert.setRecommend(1);
        Date date=new SimpleDateFormat("yyyy-MM-dd").parse("2024-12-10");
        concert.setStartTime(date);
        concert.setAddress("北京海淀区");

        count=concertService.updateConcert(concert);
        System.out.println(count);

    }

    @Test
    public void deleteConcert() throws ParseException {
        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        ConcertService concertService=(ConcertService)context.getBean("concertService");

        int concertId=14;
        int count=concertService.deleteConcert(concertId);
        System.out.println(count);
    }

    @Test
    public void count() throws ParseException {
        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        ConcertService concertService=(ConcertService)context.getBean("concertService");
        int count=concertService.count();
        System.out.println("总记录数："+count);
    }

    @Test
    public void concertById() throws ParseException {
        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        ConcertService concertService=(ConcertService)context.getBean("concertService");
        int concertId=13;
        Concert concert=concertService.selectConcertById(concertId);
        System.out.println(concert);
    }
}
